import { createRouter, createWebHistory } from 'vue-router'
import menus from '@/config/menu-config'

const routes= [
  { path: "/", name: "首页", component: () => import(`@/components/Home`)}
];

menus.forEach((item) => {
  if(item && item.items && !item.items.length){
    routes.push({
      path: `/${item.path}`,
      name: `${item.title}`,
      component: () => import(`@/components/${item.component}`)
    });
  } else {
    item.items.forEach((sub) => {
      routes.push({
        path: `/${sub.path}`,
        name: sub.title,
        component: () => import(`@/components/${sub.component}`)
      })
    })
  }
});

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router